package com.winglish.as3.exam.toeicspeaking 
{
	import com.winglish.as3.exam.toeicspeaking.impl.TSPart;
	import com.winglish.as3.utils.StringUtil;
	import com.winglish.as3.utils.NumberUtil;
	
	import flash.display.MovieClip;
	import flash.text.TextFieldAutoSize;
	import flash.events.MouseEvent;
	import flash.events.Event;
	import flash.display.Stage;
	
	/**
	 * ...
	 * @author charmjin
	 */
	public class TSPart4 extends TSAnswer implements TSPart
	{
		private var img1:Object;
		private var img2:Object;
		public function TSPart4(mc:MovieClip, data:Object, imgObj1:Object, imgObj2:Object) 
		{
			super(mc, data, 4);
			img1 = imgObj1;
			img2 = imgObj2;
		}
		
		/**
		 * 사운드재생, 녹음, 공백시간 등이 끝나고 나서 실행하는 함수.
		 * @param	no
		 */
		public function action(no:int):void {
			var mcRoot:MovieClip = _root.mcRoot;
			switch(no) {
				case 1 :	//preparing
					_root.gotoAndStop("part" + partNo + "_Q");
					mcRoot = _root.mcRoot;	//nextFrame 이동으로 mcRoot 내용이 달라지기 때문에 다시 넣기.
					mcRoot.secTxt.text = NumberUtil.itostr(String(TSData["PART" + partNo][2]).split("r")[0]);
					mcRoot.imgLoadMc.x = -img1.width / 2;
					mcRoot.imgLoadMc.addChild(img1);
					break;
				case 3:		//sound0
					mcRoot.nextFrame();
					mcRoot.secTxt.text = NumberUtil.itostr(String(TSData["PART" + partNo][4]).split("r")[0]);
					break;
				case 5 :	//sound1
					mcRoot.nextFrame();
					mcRoot.secTxt.text = NumberUtil.itostr(String(TSData["PART" + partNo][6]).split("r")[0]);
					break;
				case 7 :	//sound2
					mcRoot.nextFrame();
					mcRoot.secTxt.text = NumberUtil.itostr(String(TSData["PART" + partNo][8]).split("r")[0]);
					break;
				case 9 :	//end
					_root.gotoAndStop("part" + partNo + "_A");
					answerSet();
					break;
			}
			
		}
		
		/**
		 * 피드백 텍스트 셋팅.
		 */
		override protected function answerSet():void {
			super.answerSet();
			for (var i:uint = TSData.PART_QST_CNT[partNo - 1]; i < TSData.PART_QST_CNT[partNo]; i++) {
				var no:uint = i - TSData.PART_QST_CNT[partNo - 1];
				var mc:MovieClip = _root.mcRoot["q" + no] as MovieClip;
				if (mc) {
					mc.queTxt.autoSize = TextFieldAutoSize.LEFT;
					mc.queTxt.text = StringUtil.strReplace(StringUtil.strReplace(dataObj["quiz" + no].question,"||","|"), "|", "\n");
					if (mc.queTxt.numLines > 3) {
						StringUtil.setChangeTextFormat(mc.queTxt, { size:13 } );
					}
					if (mc.queTxt.numLines > 3) {
						StringUtil.setChangeTextFormat(mc.queTxt, { size:12 } );
					}
				}
			}
			_root.popMc.visible = false;
			_root.viewBtn.addEventListener(MouseEvent.CLICK, viewBtnClick);
			_root.popMc.closeBtn.addEventListener(MouseEvent.CLICK, closeBtnClick);
			_root.popMc.imgLoadMc0.addChild(img1);
			_root.popMc.imgLoadMc1.addChild(img2);
			_root.popMc.imgLoadMc0.x = (TSData.STAGE_WIDTH / 2) - (img1.width + img2.width + TSData.PART4_IMG_GAP) / 2;
			_root.popMc.imgLoadMc1.x = _root.popMc.imgLoadMc0.x + img1.width + TSData.PART4_IMG_GAP;
			
		}
		
		/**
		 * 나의 답변, 모범 답변 사운드 셋팅.
		 * @param	ansArr
		 * @param	recArr
		 */
		override public function soundRecordSet(ansArr:Array, recArr:Array):void {
			super.soundRecordSet(ansArr, recArr);
		}

		/**
		 * popup view btn click
		 * @param	e
		 */
		private function viewBtnClick(e:MouseEvent):void {
			_root.popMc.visible = true;
		}
		
		/**
		 * popup close btn click
		 * @param	e
		 */
		private function closeBtnClick(e:MouseEvent):void {
			_root.popMc.visible = false;
		}
		
		/**
		 * 다시풀기 버튼 클릭
		 * @param	e
		 */
		override public function reStartBtnClick(e:MouseEvent):void {
			super.reStartBtnClick(e);
			dispatchEvent(new Event("reStart", true));
			_root.gotoAndPlay("part" + partNo);
		}
	}

}